﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Business_Logic_Layer;
namespace Demo3Layer
{
    public partial class Demo : Form
    {
        public Demo()
        {
            InitializeComponent();
        }
        BusinessLogic bl = new BusinessLogic();
        //View when form load
        private void Form1_Load(object sender, EventArgs e)
        {
            dataGridView1.DataSource = bl.ShowData();
        }
        //Event insert
        private void button1_Click(object sender, EventArgs e)
        {
            bl.Insert(textBox1.Text, textBox1.Text);
            Form1_Load(sender, e);
        }
        //Event delete
        private void button2_Click(object sender, EventArgs e)
        {
            bl.Delete(textBox1.Text);
            Form1_Load(sender, e);
        }
        int dong;
        private void dataGridView1_RowEnter(object sender, DataGridViewCellEventArgs e)
        {
            dong = e.RowIndex;
            textBox1.Text = dataGridView1.Rows[dong].Cells[0].Value.ToString();
            textBox2.Text = dataGridView1.Rows[dong].Cells[1].Value.ToString();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            bl.Update(textBox1.Text, textBox2.Text);
            Form1_Load(sender, e);
        }
    }
}
